using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Sanchay
{
    public partial class AddSpareParts : Form
    {
        DataGridView dgv;
        int rowIndex;
        string partsNo;
        public AddSpareParts(DataGridView dgv1, int rowIndex1, string partsNo)
        {
            this.dgv = dgv1;
            this.rowIndex = rowIndex1;
            this.partsNo = partsNo;
            InitializeComponent();
        }

        private void AddSpareParts_Load(object sender, EventArgs e)
        {
            txtPartNo.Text = partsNo;
        }

        private void txtPurchaseInvoiceNo_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            dgv.Rows[rowIndex].Cells[0].Value = "";
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataAccess da = new DataAccess();

            string query = "INSERT INTO SpareParts (PartsNo, PartsName, BikeId, CurrentMRP,AvailableQty) VALUES (@PartsNo, @PartsName, @BikeId,@CurrentMRP,@AvailableQty)";
            SqlParameter[] param = new SqlParameter[5];

            param[0] = new SqlParameter("PartsNo", txtPartNo.Text);
            param[1] = new SqlParameter("PartsName", txtPartName.Text);
            param[2] = new SqlParameter("BikeId", 1);
            param[3] = new SqlParameter("CurrentMRP", txtMrp.Text);
            param[4] = new SqlParameter("AvailableQty", 1);
            

            if (txtPartNo.Text!="" & txtMrp.Text!="")
            {
                da.DoCommand(query,param);
                dgv.Rows[rowIndex].Cells[0].Value = txtPartNo.Text;
                dgv.Rows[rowIndex].Cells[1].Value = txtPartName.Text;
                this.Close();
            }
            else
            {
                MessageBox.Show("Please enter Parts No and/or MRP");
                
            }
            
            
        }
    }
}